<?php

include_once( '../api/session.php' );

require_once( '../api/Client.class.php' );

include_once( '../library/config.php' );
include_once( APPLICATION.'Payment.class.php' );
include_once( APPLICATION.'Paymentrequest.class.php' );

$pname = 'JaPagoJo';

include_once( 'templates/header.tmp.php' );

$c = new Client( $_SESSION['token'] );
$cdata = $c->getProfile();

$p = new Payment();
$p->setSubject( $_POST['subject'] );
$p->setAmount( $_POST['amount'] );
$p->setId_user( $cdata['data']['id'] );
$p->setName( $cdata['data']['holder']['firstName'].' '.$cdata['data']['holder']['lastName'] );
$idp = $p->insert();

$ii = 0;
foreach( $_POST['emails'] as $email ) {
	$pr = new Paymentrequest();
	$pr->setId_payment( $idp );
	$pr->setAmount( $_POST['sliders'][$ii] );
	$pr->setEmail( $email );
	$idpr = $pr->insert();
  mail( $email, 'Sol·licitud de pagament conjunt', 'Un amic et sol·licita '.$_POST['sliders'][$ii].'€ en concepte de '.$_POST['subject']."\n\nPots pagar des d'aquí: ".EMAIL_URL.'pay.php?idp='.$idp.'&email='.$email, "From: japagojo@lacaixa.es\r\n" );
  $ii++;
}
include_once( 'templates/payment_request.tmp.php' );
include_once( 'templates/footer.tmp.php' );
?>